<?php

declare(strict_types=1);

namespace App\Model\AppStore;

use Hyperf\DbConnection\Model\Model;

/**
 *  文章管理
 */
class Article extends Model
{
    protected $table = 'article';

    static function getList($cateId = 0, $page = 0, $pageNum = 20)
    {
        $where = [
            'flag' => 1,
        ];
        if ($cateId > 0) $where['category'] = $cateId;
        $start = ($page - 1) * $pageNum;
        return self::where($where)->orderBy('id', 'desc')->offset($start)->limit($pageNum)->get()->toArray();
    }

    static function getRecList($page = 0, $pageNum = 20)
    {
        $where = [
            'flag' => 1,
            'is_rec' => 1
        ];
        $start = ($page - 1) * $pageNum;
        return self::where($where)->orderBy('id', 'desc')->offset($start)->limit($pageNum)->get()->toArray();
    }

    static function getItem($id = 0)
    {
        $data = self::find($id);
        return $data ? $data->toArray() : [];
    }
}
